library(readstata13)
library(ggplot2)
library(grid)

## Set working directory
setwd()


## Read in data and define treatment
data <- read.dta13("diff_plot.dta")
data$treat <- ifelse(data$t>=0, 1, 0)
data$t <- (data$t/2) + .5


## Figure 1:
(p <- ggplot(data, aes(x=t, group=treat)) + geom_line(aes(y=control_mean), size=1.3, colour="gray60") + labs(x="Terms Until Woman Elected", y="Prob Rep. is On Women's Committee") +
  theme_minimal() + geom_line(aes(y=treat_mean), size=1.3) + geom_vline(xintercept=0, col="red", alpha=.6) +
  theme(plot.margin=unit(c(1,1,1,1), "cm"),
    axis.ticks=element_blank(),
    axis.title.y=element_text(vjust=3, size=20),
    axis.title.x=element_text(vjust=-20, size=20),
    axis.text.x = element_text(size=20),
    axis.text.y = element_text(size=20)
  ) +
  annotate("text", label="Districts That \n Elect a Woman", x=3, y=.55, col="black", size=7) +
  annotate("text", label="Districts That \n Never Elect a Woman", x=3.5, y=.28, colour="gray30", size=7) +
  scale_y_continuous(limit=c(.25,.7)) + scale_x_continuous(limit=c(-10,7)))


ggsave("~/Dropbox/Research/women/data_and_code/replication/tables_figures/diff_plot.pdf", plot = p, 
          width = 9, height = 6, units = "in", device = "pdf")


